Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor BitmapCanvas, lazily allocate canvas, fix image composition bug. #15153

Merged
merged 9 commits into from
Jan 7, 2020

Conversation

ferhatb
Copy link
Contributor

@ferhatb ferhatb commented Jan 6, 2020

Added endOfPaint call on recording canvas to allow bitmap canvas to dispose after reuse.
Moved all immediate canvas calls from BitmapCanvas into CanvasPool.
Reduced context updates by creating ContextHandle class.
Added regression tests for drawing on top of image in a single Picture.

Fixes flutter/flutter#44845
Fixes flutter/flutter#48032
Fixes flutter/flutter#44585

@ferhatb ferhatb requested a review from yjbanov January 6, 2020 21:03
@auto-assign auto-assign bot requested a review from gw280 January 6, 2020 21:03
String _prevFilter = 'none';
Object _prevFillStyle;
Object _prevStrokeStyle;
int _canvasPositionX, _canvasPositionY;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like other fields, docs here would be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

final RRect outer =
RRect.fromRectAndCorners(const Rect.fromLTRB(10, 20, 30, 40));
final RRect inner =
RRect.fromRectAndCorners(const Rect.fromLTRB(12, 22, 28, 38));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the above two indents are off

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// Fill a virtually infinite rect with the color.
void fill() {
html.CanvasRenderingContext2D ctx = context;
ctx.beginPath();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this here but not in drawColor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

html.CanvasRenderingContext2D ctx = context;
contextHandle.blendMode = blendMode;
contextHandle.fillStyle = color.toCssString();
contextHandle.strokeStyle = '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still missing how a filter applied in a drawPaint won't leak into drawColor 🤔

Example:

c.drawPaint(... pass Paint with filter...);
// at this point, because we didn't reset the previous paint the `filter` is still there.
c.drawColor(... some color and blend mode ...);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added filter = 'none';

ui.StrokeCap _currentStrokeCap = ui.StrokeCap.butt;
ui.StrokeJoin _currentStrokeJoin = ui.StrokeJoin.miter;
Object _currentFillStyle;
Object _currentStrokeStyle;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please leave a comment explaining why the above two fields need to be Object?

context.fillStyle = '';
_currentFillStyle = context.fillStyle;
context.strokeStyle = '';
_currentStrokeStyle = context.strokeStyle;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please leave a comment explaining why you have to write an empty string then read it back from context rather than assign an empty string to everything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dnoe.

});

test('Inner RRect > Outer RRect', () {
underTest.drawDRRect(rrect, rrect.inflate(1), somePaint);
underTest.apply(mockCanvas);
// Expect nothing to be called
expect(mockCanvas.methodCallLog.length, equals(0));
expect(mockCanvas.methodCallLog.length, equals(1));
expect(mockCanvas.methodCallLog.toString(), contains('endOfPaint'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: a shorter version

expect(mockCanvas.methodCallLog.single.methodName, 'endOfPaint');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


// Regression test for https://github.com/flutter/flutter/issues/44845
// Circle should draw on top of image not below.
test('Paints on top of image', () async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you forget to include a test that tests [circle, image] sequence? I saw the test included in the goldens, but it's not in this PR 🤔

@ferhatb ferhatb requested a review from yjbanov January 7, 2020 23:29
@ferhatb
Copy link
Contributor Author

ferhatb commented Jan 7, 2020

Merging on infra failure due to XCode install

@ferhatb ferhatb merged commit 27a221d into flutter:master Jan 7, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2020
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Jan 8, 2020
flutter/engine@3f52888...a50f1ef

git log 3f52888..a50f1ef --first-parent --oneline
2020-01-08 gw280@google.com Migrate flutter_runner from flutter_runner::{Thread,Loop} to fml::{Thread,MessageLoop} (flutter/engine#15118)
2020-01-07 ferhat@gmail.com Refactor BitmapCanvas, lazily allocate canvas, fix image composition bug. (flutter/engine#15153)
2020-01-07 ferhat@gmail.com Recover when browser throws on ImageElement.decode due to too many images (flutter/engine#15160)
2020-01-07 garyq@google.com Fix RectHeightStyle::kMax ascent computation bug (flutter/engine#15106)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC garyq@google.com on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
bkonyi pushed a commit to flutter/flutter that referenced this pull request Jan 9, 2020
flutter/engine@3f52888...a50f1ef

git log 3f52888..a50f1ef --first-parent --oneline
2020-01-08 gw280@google.com Migrate flutter_runner from flutter_runner::{Thread,Loop} to fml::{Thread,MessageLoop} (flutter/engine#15118)
2020-01-07 ferhat@gmail.com Refactor BitmapCanvas, lazily allocate canvas, fix image composition bug. (flutter/engine#15153)
2020-01-07 ferhat@gmail.com Recover when browser throws on ImageElement.decode due to too many images (flutter/engine#15160)
2020-01-07 garyq@google.com Fix RectHeightStyle::kMax ascent computation bug (flutter/engine#15106)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC garyq@google.com on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
@ferhatb ferhatb deleted the draw_on_image6 branch January 9, 2020 22:57
filmil pushed a commit to filmil/engine that referenced this pull request Mar 13, 2020
…bug. (flutter#15153)

* Refactor BitmapCanvas. Fix image compositing bug. Allocate canvas lazily
* Fix recording canvas test by restoring context save
* Update recording canvas test for drawColor to show multiply blend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants